package project;
import java.sql.*;
import java.io.*;
import javax.sql.*;
import java.util.*;

public class Main {
    public static void main(String[] args){
      ConnectionType connTy = new ConnectionType();
      ArrayList<ConnectionType> connList = new ArrayList<ConnectionType>();
       try {
           Class.forName("com.mysql.jdbc.Driver").newInstance();
			} catch (Exception e) {
            System.out.println("Error loading Driver");
			}

	try {
         FileInputStream fis = new FileInputStream("locations.dat");
        ObjectInputStream ois = new ObjectInputStream(fis);
    while(true){
        int i =0;
        try{
    connTy.dbInfo = (DatabaseInfo)ois.readObject();

        connTy.conn = DriverManager.getConnection("jdbc:mysql://" + connTy.dbInfo.getHostName()+":"+connTy.dbInfo.getPortNo()+"/"+connTy.dbInfo.getDatabaseName(),
		connTy.dbInfo.getUserName(),connTy.dbInfo.getPassword());
//		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/numberTrans","root","password");
    
		} catch (EOFException e){
            break;
        }
    
    ResultSet values = null;
    ResultSet primary = null;
    ResultSet tables = null;

    try {
        System.out.println(connTy.dbInfo.getDatabaseName());
    tables = connTy.conn.getMetaData().getTables("", "", "", null);

    Statement stmt = connTy.conn.createStatement();

//    rs = stmt.executeQuery("select * from numbers1");
        while (tables.next()) {

        primary = connTy.conn.getMetaData().getPrimaryKeys("", "", tables.getString(3));
            while (primary.next()) {
//            System.out.println("Table: " +tables.getString(3) + ", Primary Key: " + primary.getString(4));
            values = stmt.executeQuery("select " + primary.getString(4) + " from " + tables.getString(3));
            while (values.next()){
//                connTy.primaryValues.add(Integer.parseInt(values.getString(1)));
                System.out.print(values.getString(1) + " ");
            }
            connList.add(connTy);
            System.out.println();
            }
    }
    } catch (SQLException e) {
        System.out.println("Error");
    }
    i++;
    }///
    } catch (SQLException e) {
		System.out.println("SQLException: " + e.getMessage());
		System.out.println("SQLState: " + e.getSQLState());
		System.out.println("VendorError: " + e.getErrorCode());
        System.exit(1);
		} catch (IOException e) {
            System.out.println("File Not Found");
        } catch (ClassNotFoundException e){
            System.out.println("Class Not Found");
        }
//CompareCheck
for (int j = 1;j<connList.size();j++){
//    if (connList.get(1).primaryValues.size() == connList.get(j).primaryValues.size() ) {

    }
}
    }
//public boolean compareValues(ConnectionType connection1, ConnectionType connection2, int position1, int position2){
//    if(connection1.primaryValues.get(position1) == connection2.primaryValues.get(position2)){
//            return true;
//    } else {
//
//        return false;
//    }
//}


